const Mock = require('mockjs')

const List = []
const count = 50

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment',
    content: '@cword(10, 1024)',
    nickName: '@first',
    uId: '@increment',
    avatar: '@integer(0, 6)',
    createDate: '@datetime',
    lover: '@cname()',
    likeCount: '@integer(1, 1024)',
    commentCount: '@integer(1, 1024)',
    token: 'mock token data'
  }))
}

module.exports = [
  {
    url: '/vue-element-admin/confession/list',
    type: 'get',
    response: config => {
      console.log(config.query)
      const { orderType = 'createDate', order = 'DESC', page = 1, size = 20 } = config.query

      let mockList
      // todo 没有考虑顺序
      if (orderType === 'createDate') {
        mockList = List.sort(function(a, b) {
          return a.createDate >= b.createDate
        })
      } else if (orderType === 'likes') {
        mockList = List.sort(function(a, b) {
          return a.likeCount >= b.likeCount
        })
      } else {
        mockList = List.sort(function(a, b) {
          return a.commentCount >= b.commentCount
        })
      }

      const pageList = mockList.filter((item, index) => index < size * page && index >= size * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList,
          isFirstPage: Number(page) === 1,
          isLastPage: Number(page) >= (count / size)
        }
      }
    }
  },

  {
    url: '/vue-element-admin/confession/like',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/vue-element-admin/confession/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]

